#include <stdio.h>

const float Cost8Tons = 14.57;  // Cost of per trip for 8 tons truck, in dollor
const float Cost12Tons = 16.26; // Cost of per trip for 12 tons truck, in dollor

void main(void)
{
    int NumofTrips8Tons, NumofTrips12Tons; // 8吨和12吨货车运货的次数
    float TotalTons;                       //需要运送的总货物吨数
    printf("Please enter the gross tonnage of the cargo\n");
    scanf("%f", &TotalTons);
    printf("The total tonnage of the cargo to be transported is:%f\n", TotalTons);
    int MaxTrips8Tons, MaxTrips12Tons;
    MaxTrips8Tons = (int)TotalTons / 8;
    MaxTrips12Tons =  (int)TotalTons / 12;
    float MinCost = 10e10;              //用于保存最小成本
    int iSelected = -1, jSelected = -1; //找到的分配次数
    int i,j;
    int TotalTrips;
    for ( i = 1; i <= MaxTrips8Tons; i++)
    {
        for ( j = 1; j <= MaxTrips12Tons; j++)
        {
            if (i * 8 + j * 12 >= TotalTons)
            {
                //能够运完
                TotalTrips = i + j;
                if ((i * 1.0 / TotalTrips <= 0.6) && (j * 1.0 / TotalTrips <= 0.6))
                {
                    float TotalCost = i * Cost8Tons + j * Cost12Tons;
                    if (TotalCost < MinCost)
                    {
                        MinCost = TotalCost;
                        iSelected = i;
                        jSelected = j;
                    }
                }
            }
        }
    }
    if (iSelected>0 && jSelected>0)
    {
        printf("8 tons trunck: %d trips, 12 tons:%d trips. Minimal cost is:$%.2f",i,j,MinCost);
    }
}
